from rest_framework import generics
from django_filters import rest_framework as filters
from django.db.models import Q
from .models import Answer, Comment


class AnswerFilter(filters.FilterSet):
    min_agree_num = filters.NumberFilter(name="agree_count", lookup_expr='gte', label="最小赞同数", help_text='最小赞同数')
    max_agree_num = filters.NumberFilter(name="agree_count", lookup_expr='lte', label="最大赞同数", help_text='最大赞同数')
    content = filters.CharFilter('content', lookup_expr='icontains', help_text='回答的内容')

    class Meta:
        model = Answer
        fields = ['content', 'min_agree_num', 'max_agree_num']


class CommentFilter(filters.FilterSet):
    class Meta:
        model = Comment
        fields = ['user', 'answer']
